home *** CD-ROM | disk | FTP | other *** search
/ Resource for Source: C/C++ / Resource for Source - C-C++.iso / misc_src / knowhow4 / example.doc < prev    next >
Text File  |  1995-11-01  |  32KB  |  841 lines

  1. To know more about working in KNOW-HOW lets construct few examples.
  2.     1. Blocks. The most simple way of adding complex mouse support
  3. to you objects is to use ObjectKit class and its derivatives. This
  4. class itself is a container for Visible derivatives, and at the
  5. same time a Visible's child:
  6. class Kit : public Visible
  7. ....
  8. class ObjectKit : public Kit
  9.     {
  10.     Visible** list;
  11.     ....
  12.     }
  13.  
  14. First block class - Bl - is the ObjectKit child, whose constructor
  15. add to its list the base Window and Element for CANCEL operation.
  16. Next class - Block - have also PGUP, PGDN, LEFT, RIGHT and so on
  17. buttons.
  18.  
  19.     Now lets use Write class (simple text editor) to produce
  20. text editor with buttons (BLKWRITE file).
  21.  
  22. #include "write.h"     // Write class
  23. #include "blk.h"       // Block class
  24.  
  25. class BlockWrite : public Block
  26.     {
  27.     public:
  28.         Write* write;  // Attention! It is good idea to make it public.
  29.  
  30.         BlockWrite(rect coord,  // Window coordinates (rect defined in GEOM.H)
  31.     char* fname = "",       // Swap file name, used ONLY if no upper
  32.                                 // level container is used.
  33.     char* fileName = "work.txt",  // Text file to edit
  34.     char* h = "",           // Window header
  35.     int s = 0,              // Shadow width, pixels
  36.     int res = 0,                         // See Visible.h
  37.     BORDERS b_type = SHOW_BORDER,        // See Carcase.h
  38.         BORDERS write_border = SHOW_BORDER,  // See Carcase.h
  39.     BORDERS hdr_b_type = SHOW_BORDER,    // See Carcase.h
  40.     int pat = 0,                         // Edit field pattern
  41.     int write_pat = 0,                   // Pen color
  42.     int hdr_pat = 0,                     // Header fill pattern
  43.     int elem_pat = 0);                   // Buttons fill pattern
  44.  
  45.            virtual void rearrange(); // After changing of size of the base
  46.                                   // window, you should call this function
  47.                                   // which will change coordinates of other
  48.                                   // objects.
  49.         virtual void hide();      // Remove from screen and maybe any other
  50.                                   // functions (like SAVE - Y/N querry)
  51.     };
  52.  
  53.     Write* become data member of block class, and we define constructor
  54.     to initialize it. Remember that if you put pointer to container,
  55.     no further call to delete is necessary. Object's destructor will
  56.     delete all the objects belonging to it.
  57.  
  58. Constructor:
  59.     BlockWrite::BlockWrite(rect coord, char* fname, char* fileName,
  60.         char* h, int s, int res, BORDERS b_type, BORDERS write_border,
  61.         BORDERS hdr_b_type, int pat, int write_pat, int hdr_pat,
  62.         int elem_pat)
  63.     : Block(coord, fname, h, s, res, b_type, hdr_b_type, pat, hdr_pat,
  64.             elem_pat)
  65.     {
  66.     rect r = textRect(w1->bound());  // Get size of base window.
  67.     r.origin.Y += 2;
  68.     r.corner.Y -= (1 + textY(s));
  69.     r.origin.X += 3;
  70.     r.corner.X -= (3 + textX(s));
  71.  
  72.     Construct text editor:
  73.     write = new Write(r, fileName, "", "", 0, write_border, NO_BORDER,
  74.            write_pat, 0);
  75.     The following function will modify "ret" flag of this object. This
  76. result to the changes in its behaviour. If we leave Write - we'll leave
  77. container to.
  78.     write->set_ret(1);
  79. Put object to container. Write object becomes first, this mean that it
  80. will have control when Block becomes active.
  81.     insert(write, 1);
  82. Now we need to link buttons, write object, and actions. For example, if
  83. LEFT button is pressed, write object become active and get message AC_LEFT.
  84. It will process message and return control to the button (if it is CANCEL
  85. button, block will loose the control - see BL.H and SCI discussion above).
  86.     assign(write, left_element, AC_LEFT);
  87.     assign(write, right_element, AC_RIGHT);
  88.     assign(write, up_element, AC_UP);
  89.     assign(write, dn_element, AC_DOWN);
  90.     assign(write, cancel_element, AC_CANCEL);
  91.     assign(write, pg_up_element, AC_PG_UP);
  92.     assign(write, pg_dn_element, AC_PG_DN);
  93.     }
  94.  
  95.     rearrange() function use new coordinates of base window to resize other
  96. objects in container.
  97.  
  98. void BlockWrite::rearrange()
  99.     {
  100.     Block::rearrange();              // Base window and buttons
  101.     rect r = textRect(w1->bound());  // Get size
  102.     int s = w1->get_shadow();
  103.     r.origin.Y += 2;
  104.     r.corner.Y -= (1 + textY(s));
  105.     r.origin.X += 3;
  106.     r.corner.X -= (3 + textX(s));
  107.     write->repose(r);                // Change coordinates of write object.
  108.     }
  109.  
  110.     Hide object is necessary to explicitely call write->hide(). The reason
  111. is that editor removes itself from memory when it is not in use.
  112.  
  113. void BlockWrite::hide()
  114.     {
  115.     write->hide();
  116.     w1->hide();
  117.     }
  118.  
  119. 2. Second example. Non-container classes.
  120.     KNOW-HOW.SLANG is the (window-independent) basic-like language.
  121. As the example KNOW-HOW include the derivative KNOW-HOW.SLANG.DRAW. Base
  122. Slang was overloaded and BGI-specific functions becomes available. This
  123. class is called OOPic (Object-Oriented Pictures ? Sorry, try something
  124. better if you do not like it).
  125.     Now lets write the program which use OOPic to draw pictures in the window.
  126.  
  127. #include "window.h"
  128. #include "oopic.h"
  129.  
  130. class KH_OOPic : public OOPic, public Window
  131.     {
  132.     public:
  133.         KH_OOPic(rect coordinates) : OOPic(), Window(coordinates) {}
  134.         virtual void show();  // All drawing, including program execution.
  135.         virtual void exe(int act = 0); // User interface
  136.     };
  137.  
  138.     The constructor initialize window and interpreter. The show() function
  139. draws window and then run OOPic program.
  140.     The exe() function is of special interest. If we want to support some
  141. dialog with user we should process corresponding events.
  142.  
  143. void KH_OOPic::show()
  144.     {
  145.     Window::show();       // Show window
  146.     if(program != NULL)     // If program is loaded
  147.         {
  148.         rect r = user_screen();     // Set clip area
  149.         setviewport(r.origin.X, r.origin.Y, r.corner.X, r.corner.Y, 1);
  150.     basic(program);                                // Run program
  151.         setviewport(0, 0, getmaxx(), getmaxy(), 1);  // Restore clip area
  152.         }
  153.     }
  154. ///////////////////
  155. void KH_OOPic::exe(int act)
  156.     {
  157.     e.what = act ? KEYEVENT : NOEVENT;    // act or user input
  158.  
  159.     switch(act)  // Messages are replaced by keyboard events. Trick.
  160.     {
  161.     case AC_LEFT:   e.key = EVENT_LEFT; break;
  162.     case AC_RIGHT:  e.key = EVENT_RIGHT; break;
  163.     case AC_UP:     e.key = EVENT_UP; break;
  164.     case AC_DOWN:   e.key = EVENT_DN; break;
  165.     case AC_PG_UP:  e.key = EVENT_PG_UP; break;
  166.     case AC_PG_DN:  e.key = EVENT_PG_DN; break;
  167.     case AC_CTRL_PG_UP: e.key = EVENT_CTRL_PG_UP; break;
  168.     case AC_CANCEL: e.key = (isRet(RET_REMOVE))
  169.         ? EVENT_ALT_F3 : EVENT_ESC;
  170.         break;
  171.     case AC_OK:     e.key = EVENT_F2; break;
  172.     }
  173.     mouseHideCursor();
  174.     if(!act)
  175.     hilite();
  176.  
  177.     int on = 0;
  178.     mouseShowCursor();
  179.     rect r = user_screen();
  180.     while(1)
  181.     {
  182.     mouseShowCursor();
  183.     if(!act && !(e.what == MOUSEEVENT && !on)) // Get user-produced event
  184.         get_event();                           // or process "act" message
  185.     else
  186.         on = 1;
  187.     mouseHideCursor();
  188.  
  189.     if(e.what == KEYEVENT)
  190.             {
  191.         switch(e.key)
  192.         {
  193.         case EVENT_RIGHT: lt.X += 8; break;
  194.         case EVENT_LEFT: lt.X = lt.X < 8 ? 0 : lt.X - 8;  break;
  195.         case EVENT_UP: lt.Y = lt.Y < 8 ? 0 : lt.Y - 8; break;
  196.         case EVENT_DN: lt.Y += 8; break;
  197.         case EVENT_HOME:  lt.X = 0; break;
  198.         case EVENT_PG_UP:
  199.             lt.Y = lt.Y < r.height() ? 0 : r.height(); break;
  200.         case EVENT_END:   lt.X += r.width(); break;
  201.         case EVENT_PG_DN: lt.Y += r.height(); break;
  202.         case EVENT_CTRL_PG_UP: lt.Y = 0; break;
  203. Put your attention to the following messages. They made current class
  204. compatible with other KNOW-HOW classes and messages exchange protocol.
  205.                 case EVENT_F1: global_i[0] = action_type; return;
  206.         case EVENT_ESC: global_num = 0;
  207.             global_i[0] = AC_NULL; return;
  208.         case EVENT_F6:
  209.         case EVENT_F10:
  210.         case EVENT_TAB:
  211.         case EVENT_ALT_F3:
  212.         case EVENT_ALT_F4:
  213.         case EVENT_ALT_TAB:
  214.             unhilite(); global_num = 1;
  215.             global_i[0] = 0; return;
  216.         case EVENT_F2:
  217.         case EVENT_RETURN :  unhilite(); global_num = 1;
  218.             global_i[0] = action_type; return;
  219.         }
  220.             if(program != NULL)     // If program is loaded
  221.                 {
  222.                 clrscr();
  223.                 setviewport(r.origin.X, r.origin.Y, r.corner.X, r.corner.Y, 1);
  224.                 basic(program);                              // Run program
  225.                 setviewport(0, 0, getmaxx(), getmaxy(), 1);  // Restore clip area
  226.                 }
  227.             }
  228.     else
  229.         {
  230.         if(!mouse_in(e.where()))    // Mouse pressed outside
  231.         {
  232.         unhilite();
  233.         global_num = 0; global_i[0] = AC_NULL;
  234.         return;
  235.         }
  236.         }
  237.     if(act)    // leave object and return to the object which calls it
  238.         {      // after single processing of "act" command
  239.         global_num = 1;
  240.         return;
  241.         }
  242.     }
  243.     }
  244. Here is the example of usage of the KH_OOPic.
  245. //////////////
  246. void main()
  247.     {
  248.     if(!init_KNOW_HOW())
  249.         return;
  250.     setfillstyle(SOLID_FILL, pColorSet->colors.BAK_COLOR);
  251.     bar(0, 0, getmaxx(), getmaxy());
  252.  
  253.     KH_OOPic s(rect(10, 0, 60, 24));
  254.  
  255.     s.show();
  256.     s.set_program(s.load_program("work.bas"));
  257.     s.show();
  258.     s.exe();
  259.  
  260.     close_KNOW_HOW();
  261.     closegraph();
  262.     }
  263.  
  264.  
  265. 3. Building the Application.
  266.     Now lets write the program which use KH_OOPic to draw pictures and Write
  267. to edit programs. It also should print pictures using KNOW-HOW.Print with
  268. any deformation.
  269.  
  270. WHAT WE NEED.
  271.  
  272.     The menu tree of application would be designed in the following manner
  273. ("Nothing" means that it is demo example only):
  274.  
  275. File    Edit    Options    Methods    Scripts    Print
  276.  |       |         |          |          |         |
  277.  |       |      Nothing    Nothing       |     PrintPanel
  278.  |       |                               |
  279.  |       |                              Play -->
  280.  |       |                 KH_OOPic    Record ->|
  281.  |       |                BlockWrite    Stop -->|
  282.  |    Nothing                          Macros ->|
  283.  |                                      Edit -->|
  284.  |                                              |
  285.  New                                            |
  286.  Open ------------> F                           |
  287.  Save ------------> I <--------------------------
  288.  save Pcx --------> L
  289.  save pcx B&W ----> E
  290.  About              system  -------> Context specific action
  291.    |
  292.  Board
  293.  
  294. File VECTOR.H
  295.  
  296.     VECTOR 1.0 - The vector images Editor.
  297.     (C) Stepan S. Vartanov, 1994.
  298.  
  299.     ATTENTION !!! This product needs the KNOW-HOW 4.x interface library
  300.           and (desirable) KNOW-HOW 1.x PRINT MANAGER SYSTEM
  301.  
  302. All headers we need should be included here.
  303.  
  304. #include "khoopic.h"  // khoopic.h or blkoopic.h could be used
  305. #include "ask_hot.h"  // Button which may be hidden and macros append
  306.                       // function
  307. #include "icon.h"     // "About" cartoon film
  308. #include "board.h"    // "About" system
  309.  
  310.  
  311. #include "prn_form.h"    // Printer setup
  312. #include "appkit.h"      // ApplicationKit
  313. #include "blkwrite.h"    // write.h or blkwrite.h could be used
  314. #include "print.h"       // Print manager
  315.  
  316. #include "b&w.h"         // PCX color <-> B&W convertor
  317. #include "help.h"        // Help system
  318.  
  319. #include "bllmenu.h"     // Line (main) menu
  320. #include "blkmenu.h"     // Box menu
  321.  
  322. #include "blfsys.h"      // File system
  323. #include "window.h"
  324.  
  325.     Registration of the "user-defined functions". When the program works,
  326. different objects gets and losts control (focus of input in WINDOWS).
  327. UDFunctions are called in this moment.
  328.  
  329. enum { AC_FILE_MENU = 101, AC_EDIT_MENU, // items of the line menu
  330.        AC_OPTIONS_MENU, AC_METHOD_MENU, AC_SCRIPT_MENU, AC_PRINT_MENU,
  331.  
  332.        AC_NEW, AC_OPEN, AC_SAVE, AC_SAVE_AS_PCX,  // go here from "file_menu"
  333.        AC_SAVE_AS_PCX_BW, AC_ABOUT,
  334.  
  335.        AC_SCRIPT_PLAY, AC_SCRIPT_RECORD, // go here from "script_menu"
  336.        AC_SCRIPT_END, AC_MACROS_KEEP, AC_EDITOR,
  337.  
  338.        AC_PROGRAM_EDIT,  AC_PROGRAM_RUN, // Program editor and interpreter
  339.  
  340.        AC_ASK_EXIT, // Before exit ask Y/N
  341.  
  342.        AC_PRINT,    // go here from "form" (print setup)
  343.  
  344.        AC_MOVE_APPL, AC_RESIZE_APPL,  // If you want to move / resize base
  345.  
  346.        AC_FILE // After File system was executed
  347.     };
  348.  
  349.     Class Vector. It include pointers to all its objects. The only reason
  350. is possibility of calls for functions, which are not virtual members
  351. of Visible class. If you do not need it - use ApplicationKit::list[i]
  352. instead.
  353.  
  354. class Vector : public ApplicationKit
  355.     {
  356.     protected:
  357.     int DATA_FILE; // The way we come to the File system (f.e. from Open
  358.                        // or Save).
  359.  
  360.     Window* w1;                   // System base window
  361.         BlockLineMenu* menu;          // Main menu
  362.     BlockMenu* file_menu;         // New, Open, Save...
  363.     BlockFile* file_sys;          // List of files
  364.     BlockMenu* script_menu;       // Script Manager
  365.     PrintManager* print;          // Print Manager
  366.     GrafBuffer* buffer;           // Buffer of Print and PCX managers
  367.     Form* form;                   // Printer setup
  368.     Write* editor;                // Text (program) editor
  369.         BlockWrite* script_editor;    // Text (script) editor
  370.         KH_OOPic* vector;             // Picture draw window.
  371.  
  372.     public:
  373.     Vector(char* fileName,        // File for swapping
  374.            char* buf_name,        // Name of Print/PCX tmp. swap file
  375.            int obj_number = 0,    // Number in upper level container
  376.            int step = 1);         // Step in objects numeration.
  377.     virtual ~Vector();            // Destructor
  378.     virtual void show();          // Show some objects
  379. //    virtual void rearrange();     // Used if resize facility is available
  380.         virtual int application(int n);  // User-defined functions
  381.     void prepare_files();         // Before file_system
  382.         virtual int active() { return w1->active(); }  // Is visible?
  383.     };
  384.  
  385. #endif __VECTOR_H_
  386.  
  387. When you build application, you need to create 4 new files. Header (below)
  388. is the first, and the other are:
  389.     VECTOR.CPP file. Contain constructor, show(), rearrange() and possible,
  390. some service functions.
  391.     VECTAPPL.CPP file. application() function. Switch to call user-defined
  392. functions.
  393.     VECTMAIN.CPP file. Contains main() function.
  394. Lets construct this files together.
  395.  
  396. File VECTOR.CPP:
  397.  
  398. #include "vector.h"   // We include header
  399.  
  400. int application(int) { return 0; }  // Dummy function - will not be in use
  401. // If user want use class (like Vector class), the Vector::application()
  402. // overload it. If user use set of non-class functions (bad idea), it
  403. // will be overloaded with non-class application().
  404.  
  405. rect r_draw_size;      // == bound of draw object, expanded or not.
  406.                        // Used in general for move and resize functions.
  407.  
  408. Vector::Vector(char* fileName, char* bufName, int obj_num, int step)
  409.     : ApplicationKit(step, loc(39, 13))
  410.     {
  411.     set_object_number(obj_num);  // To use in upper-level container
  412.     DATA_FILE = 1;
  413. // Constructors for objects
  414. //////////////////////////////// Base Window
  415.     rect r_base(0, 0, 80, 25);
  416.     w1 = new Window(r_base, fileName, "", 0, BUTTON_BORDER, NO_BORDER,
  417.            MOVE | RESIZE, 0, 0);
  418. //////////////////////////////// Interpreter
  419.     rect r_vector(0, 2, 40, 25);
  420.     vector = new KH_OOPic(r_vector);
  421. ////////////////////////////// Line Menu
  422.     rect r_menu(5, 0, 80, 2);
  423.     static char* hotMenuList = "FEOMSP";       // hot for line menu
  424.     static char* menuList[] = { " File", " Edit", " Options",
  425.     " Method", " Script", " Print", "" };
  426.     menu = new
  427.     BlockLineMenu(r_menu, "", hotMenuList, menuList, rect(0, 24, 79, 25),
  428.            0, NULL, NULL, BUTTON_BORDER, 16, 16, 16);
  429. //////////////////////////////// Resize/Move object - menu with two icons.
  430. // To be used with MOVE / RESIZE facilities
  431. //    rect r_resize_panel(0, 0, 5, 3);
  432. //    static int ic_resize_list[] = { I_MOVE, I_RESIZE, 0 };
  433. //    loc l = pScreenSet->g_mode == VGAHI ? loc(4, 4) : loc(4, 2);
  434. //    resize_panel = new IconMenu(r_resize_panel, "", "",
  435. //              NULL, 1, 1, SMALL_ICON, ic_resize_list, l,
  436. //              rect(0, 0, 25, 80), 0, NULL, NULL, FIXED, 0,
  437. //              BUTTON_BORDER, NO_BORDER);
  438. //////////////////////////////// Script editor. Popup.
  439.     rect r_script_edit(10, 5, 70, 20);
  440.     script_editor = new
  441.     BlockWrite(r_script_edit, "", "work.txt", "Editor", 6,
  442.         MOVE | RESIZE, SHOW_BORDER, SHOW_BORDER, SHOW_BORDER,
  443.         0, 0, 0, 16);
  444. ////////////////////////// Program editor. Staked.
  445.     rect r_edit(40, 2, 80, 25);                 // Editor
  446.     editor = new Write(r_edit, "work.vec", "", "Editor", 6,
  447.         SHOW_BORDER, SHOW_BORDER, 0, 0);
  448. ////////////////////////// New - Open - Save - ... menu
  449.     rect r_file = rect(5, 3, 30, 16);
  450.     static char* hotFileList = "NOSPB?";             // hot for file menu
  451.     static char* fileList[] = { " New ", " Open ",
  452.     " Save", " save As pcx", "save as pcx B&w",
  453.     " << ? >> ", "" };
  454.  
  455.     file_menu = new BlockMenu(r_file, "", " Files ", 6, hotFileList,
  456.     fileList, rect(0, 24, 79, 25), 0, NULL, NULL,
  457.            FIXED, SHOW_BORDER, SHOW_BORDER, 16, 16, 16, 16);
  458. /////////////////////////// File list
  459.     file_sys = new BlockFile("File");
  460. ////////////////////////// Scripts menu
  461.     rect r_script = rect(50, 4, 69, 17);
  462.     static char* items_script[] = { " Play", " Record", " Stop", " Macros",
  463.     " Edit", "" };
  464.     static char* hotScriptList = "PRSME";         // for script menu
  465.     script_menu = new BlockMenu(r_script, "", " Scripts ", 6,
  466.     hotScriptList, items_script, rect(0, 24, 79, 25), 0, NULL, NULL,
  467.            FIXED, SHOW_BORDER, SHOW_BORDER, 16, 16, 16, 16);
  468. ///////////////////////////
  469.     r_draw_size = vector->user_screen();
  470. ///////////////////////////// Print system.
  471.     rect r = vector->user_screen();
  472.     r.corner.Y -= 1;
  473.     buffer = new GrafBuffer(loc(750, 550), bufName, r);
  474.     print = new PrintManager(EPSON9, DD, 1, rect(1, 1, 1, 1), 0,
  475.                           PAPER_ON, 6);
  476.     form = new Form();
  477. ///////////////////////////
  478. // We add objects to the container "kit". Order is significant.
  479.     background(w1);
  480.     add(menu);
  481.     add(vector);
  482.     add(editor);
  483.  
  484. //    add(resize_panel);    // MOVE and RESIZE the program kit
  485.  
  486.     add(file_menu);       // go here from "menu" FILE
  487.     add(file_menu);       // go here from "menu" EDIT    (really - not).
  488.     add(file_menu);       // go here from "menu" OPTIONS
  489.     add(file_menu);       // go here from "menu" METHODS
  490.     add(script_menu);
  491.     add(form);
  492.  
  493.     add(file_sys);        // go here from "file_menu", "script_menu"...
  494.     add(file_sys);
  495.     add(file_sys);
  496.     add(file_sys);
  497.     add(script_editor);
  498.  
  499. // We set the numbers (or the names, which may be transformed to number
  500. // of the objects which will be called after exiting from current object
  501. // with ENTER-like command.
  502. //    set_point(fill_prompt, fill_panel);
  503. // we set, that after exiting from object with ENTER-like command it will
  504. // call function N + no of menu choice - 1 from appl1.cpp file,
  505. // and then call object No ... in list. Note that it can overwrite the
  506. // set_point settings.
  507. //    assign(w1, resize_panel, AC_MOVE); // Reserved
  508.  
  509.     assign(file_menu, menu, AC_FILE_MENU);
  510.     assign(file_sys, file_menu, AC_NEW); // ATTENTION!!! OPEN and SAVE
  511.                   // points to the same file_sys object.
  512.     assign(file_sys, script_menu, AC_SCRIPT_PLAY);
  513.     assign(0, form, AC_PRINT);
  514.     assign(0, file_sys, AC_FILE);
  515.     assign(0, script_editor, AC_EDITOR);
  516.     assign(0, editor, AC_PROGRAM_RUN);
  517.     assign(editor, vector, AC_PROGRAM_EDIT);
  518.  
  519.     set_exit(AC_ASK_EXIT);
  520.  
  521. // We can set the numbers (or the names, which may be transformed to number
  522. // of the objects which will be called after exiting from current object
  523. // with ESC-like command. If current object was called from another
  524. // object, its callFrom flag will be changed, correspondingly, so it is not
  525. // absolutely necessary : kit->set_call(file_menu, menu)...
  526. // default object hides itself after exiting. But to obtain first-second-third...
  527. // level menu cascade we must change return flag to 2. In this case menu
  528. // will hide itself after exiting with ESC-like command, and will not -
  529. // if the next menu must be called (ENTER command).
  530.     menu->set_ret(RET_CANCEL | RET_STACKED | RET_SHOW);
  531.     file_menu->set_ret(RET_MOUSE | RET_CANCEL | RET_TRANSFER);
  532.     form->set_ret(RET_MOUSE | RET_CANCEL | RET_OK);
  533.     script_menu->set_ret(RET_CANCEL | RET_MOUSE | RET_TRANSFER);
  534.     file_sys->set_ret(RET_CANCEL | RET_MOUSE | RET_TRANSFER);
  535.     script_editor->set_ret(RET_OK | RET_MOUSE | RET_CANCEL);
  536.  
  537.     w1->set_ret(RET_STACKED);
  538. //    resize_panel->set_ret(RET_STACKED | RET_SHOW);
  539.     editor->set_ret(RET_STACKED | RET_SHOW);
  540.     vector->set_ret(RET_STACKED | RET_SHOW);
  541.  
  542. // Setting of the context help. ATTENTION!!! only ObjectKit childs have help.
  543.     menu->set_help_context("common  ");
  544.     file_menu->set_help_context("file_sys");
  545.     script_menu->set_help_context("script  ");
  546.     form->set_help_context("printset");
  547.     }
  548. /////////////////////////////// Destructor.
  549. Vector::~Vector()
  550.     {
  551.     editor->hide();
  552.     delete print;
  553.     delete buffer;
  554.     }
  555. ///////////////////////// We need to show only few objects.
  556. void Vector::show()
  557.     {
  558.     mouseHideCursor();
  559.     WindowManager::show_window(w1);
  560.     vector->set_program(vector->load_program("work.vec"));
  561.     WindowManager::show_window(vector);
  562.     WindowManager::show_window(editor);
  563.     WindowManager::show_window(menu);
  564. //    WindowManager::show_window(resize_panel);
  565.  
  566.     moveTo(1);
  567.     mouseShowCursor();
  568.     }
  569. //////////////////////////
  570.  
  571.  
  572. File VECTAPPL.CPP
  573. Here is the simplified version of application(). It means that only
  574. few options are available. This is for simplicity only, source codes of
  575. library contain complete program.
  576.  
  577. #include "vector.h"   // Vector class
  578. #include <stdio.h>
  579. #include <conio.h>
  580. #include <string.h>
  581. #include "global.h"   // Global variables
  582. #include <dos.h>
  583.  
  584. enum { SAVE = 1, DONT_SAVE };  // Picture status: changed or not.
  585.  
  586. This enumeration is used by file system. It keep the pre-history of call to
  587. file_sys (F.e. from Open or Save)
  588. enum { FILE_NEW = 30, FILE_OPEN, FILE_SAVE, FILE_SAVE_AS_PCX,
  589.        FILE_SAVE_AS_PCX_BW,
  590.        SCRIPT_PLAY, SCRIPT_RECORD, SCRIPT_END, MACROS_KEEP, TEXT_EDIT };
  591. /////////////////////////////////////////////////////////////////////////////
  592. //------> The following part is common for programs with SCRIPTS <---------\\
  593. void file_refresh()             // Used to get previous script name from stack
  594.     {                           // Scripts and macroses could (with some
  595.     scriptMode = GO;            // Limitations) be nested.
  596.     delete scriptFileName;
  597.     scriptFileName = NULL;
  598.     mac_status mac = macros_pop();         // Obtain previous status
  599.     delete mac.file;
  600.     }
  601. //------>    The above part is common for programs with SCRIPTS    <-------\\
  602. /////////////////////////////////////////////////////////////////////////////
  603. // File preparing system. Not necessary but strongly reckomended.
  604. void Vector::prepare_files()
  605.     {
  606.     delete global[1]; delete global[2];
  607.     global[1] = strdup("work"); global[2] = strdup("");
  608.     (file_sys->file_system)->setItems();
  609.     }
  610. /////////////////////////////////////////////////////////////////////////////
  611. // Board (window with PCX in it) is displayed and the simple movie is
  612. // runned in it. Icons with few fazes of demo are showed one after another.
  613. void about()
  614.     {
  615.     Board* board = new Board(rect(5, 5, 65, 20), "about.pcz",
  616.               "about.pcy", "A B O U T", 8, 0, 16);
  617.     board->show_window();
  618.  
  619.     Icon i(loc(1, 1), 2, LARGE_ICON, SHOW_BORDER);
  620.     char* file = i.icon_open();
  621.  
  622.     FILE *stream;
  623.     if((stream = fopen(file, "r+b")) == NULL)
  624.     return;
  625.     loc size = icon_size(LARGE_ICON);
  626.     int i_size = ((size.X + 1 + 7) >> 3 << 2) * (size.Y + 1) + sizeof(imageP);
  627.     imageP image = (imageP)malloc(i_size + 10);
  628.     while(1)
  629.         {
  630.         for(int j = 1; j < 9; j++)
  631.             {
  632.             get_image(stream, j, image, i_size);
  633.             putimage(screenXL(8), screenYT(8), image, COPY_PUT);
  634.             delay(20);
  635.             if(eventavail(KEYEVENT | MOUSEEVENT,
  636.                MCleftDn | MCrightDn))
  637.                 break;
  638.             }
  639.         if(eventavail(KEYEVENT | MOUSEEVENT,
  640.                MCleftDn | MCrightDn))
  641.                 break;
  642.         }
  643.     get_event();
  644.     fclose(stream);
  645.     delete image;
  646.     board->hide();
  647.     delete board;
  648.     }
  649. /////////////////////////////////////////////////////////////////////////////
  650. // User-defined functions. It is good idea to write all functions, even
  651. // it they do nothing but only passes the control from one menu to another.
  652. // To know more about this topic see discussion about Simplified User
  653. // Interface in KNOW_HOW.TXT.
  654.  
  655. int Vector::application(int n)
  656.     {
  657.     rect r = vector->user_screen(); // If Block_KH_OOPic used, use
  658.                                     // (vector->vector->)user_screen()
  659.     loc mspos = e.where();          // Mouse position
  660.  
  661.     sound(100); delay(100); nosound();     // I want some beeps
  662.  
  663.     switch(n)
  664.     {
  665. //    case AC_MOVE:                  // We do not support MOVE and RESIZE
  666. //        global_i[0] = AC_MOVE;     // in this simple application.
  667. //        return 0;                  // But it is not difficult to do.
  668. //    case AC_RESIZE:                // Use KNOW-HOW.DRAW as the example.
  669. //        global_i[0] = AC_RESIZE;
  670. //        return 0;
  671.  
  672.     case AC_FILE_MENU:       // Go from line menu to the corresponding
  673.     case AC_SCRIPT_MENU:     // objects. We only pass the control here.
  674.         return 2;            // Call the next menu.
  675.         case AC_EDIT_MENU:       // This 3 menu positions are temporarly
  676.     case AC_OPTIONS_MENU:    // empty. You could develope this
  677.     case AC_METHOD_MENU:     // application using them. But now they
  678.             return 0;            // returns 0 - no action or control pass.
  679.  
  680.     case AC_PRINT_MENU:      // Pass the control to the Printer setup
  681.         return 2;            // form.
  682.  
  683.     case AC_PRINT:           // Print to printer. To be changed.
  684.         return 1;
  685.     case AC_NEW:                          // Load empty program file.
  686.             editor->unload_file();            // See WRITE.H
  687.             editor->set_swap("noname.vec");
  688.             editor->set_header("noname.vec");
  689.             editor->show();
  690.         return 1;            // Hide menu.
  691.     case AC_OPEN:
  692.         prepare_files();                       // Prepare file list
  693.         (file_sys->edit)->put_string("*.vec"); // Set new file mask
  694.         DATA_FILE = FILE_OPEN;                 // Remember pre-history
  695.         return 2;                              // Call next object
  696.     case AC_SAVE:
  697.         prepare_files();
  698.         (file_sys->edit)->put_string("*.vec");
  699.         DATA_FILE = FILE_SAVE;
  700.         return 2;
  701.     case AC_SAVE_AS_PCX:
  702.         prepare_files();
  703.         (file_sys->edit)->put_string("*.pcx");
  704.         DATA_FILE = FILE_SAVE_AS_PCX;
  705.         return 2;
  706.     case AC_SAVE_AS_PCX_BW:
  707.         prepare_files();
  708.         (file_sys->edit)->put_string("*.pcx");
  709.         DATA_FILE = FILE_SAVE_AS_PCX_BW;
  710.         return 2;
  711.     case AC_ABOUT:
  712.         about();
  713.             return 1;
  714. //------> The following part is common for programs with SCRIPTS <---------\\
  715.     case AC_SCRIPT_PLAY:
  716.         DATA_FILE = SCRIPT_PLAY;
  717.         prepare_files();
  718.         (file_sys->edit)->put_string("*.sc");  // set mask for file system
  719.         return 2;
  720.     case AC_SCRIPT_RECORD:                          // recording of script
  721.         prepare_files();
  722.         DATA_FILE = SCRIPT_RECORD;
  723.         (file_sys->edit)->put_string("*.sc");
  724.         return 2;
  725.     case AC_SCRIPT_END:                        // end of script recording.
  726.         DATA_FILE = SCRIPT_END;
  727.         file_refresh();
  728.         return 1;
  729.     case AC_MACROS_KEEP:
  730.         DATA_FILE = MACROS_KEEP;
  731.  
  732.         if(scriptMode == PLAY)
  733.         {
  734.         scriptMode = GO;
  735.         return 1;
  736.         }
  737.  
  738.         file_refresh();
  739.         prepare_files();
  740.         (file_sys->edit)->put_string("*.sc");
  741.  
  742.         return 2;
  743. //------>    The above part is common for programs with SCRIPTS    <-------\\
  744.     case AC_EDITOR:
  745.         DATA_FILE = TEXT_EDIT;
  746.         file_refresh();
  747.         prepare_files();
  748.         (file_sys->edit)->put_string("*.sc");
  749.         return 2;
  750.         case AC_PROGRAM_EDIT:               // Editor and interpreter call
  751.             return 2;                       // one to another. But after
  752.         case AC_PROGRAM_RUN:                // Interpreter we do nothing but
  753.             while(vector->play_used != 0)   // pass control, and after editor
  754.                 delete vector->playpop();   // we unload old version of the
  755.                                             // program,refresh system settings
  756.             delete vector->program;         // and load new, edited program.
  757.             vector->error = 0;
  758.             vector->set_program(vector->load_program(editor->getFileName()));
  759.             vector->show();
  760.             return 0;
  761.  
  762. // Exit program.
  763.     case AC_ASK_EXIT:
  764.         return ask_exit();  // Return 0 or 1 and pass control as it is.
  765.  
  766.     case AC_FILE:            // Using DATA_FILE pre-history, work with
  767.             switch(DATA_FILE)    // files.
  768.                 {
  769.                 case FILE_OPEN:
  770.                     editor->unload_file();
  771.                     editor->set_swap(global[global_i[1]]);
  772.                     editor->set_header(global[global_i[1]]);
  773.                     WindowManager::hide_window();   // Hide file_sys
  774.                     WindowManager::hide_window();   // Hide file_menu
  775.                     editor->show();
  776.                     moveTo(get(editor));
  777.                     return 0;
  778.                 case FILE_SAVE:
  779.                     editor->set_swap(global[global_i[1]]);
  780.                     editor->set_header(global[global_i[1]]);
  781.                     WindowManager::hide_window();   // Hide file_sys
  782.                     WindowManager::hide_window();   // Hide file_menu
  783.                     editor->swap();
  784.                     editor->show();
  785.                     moveTo(1);
  786.                     return 0;
  787.                 case AC_SAVE_AS_PCX:      // To be changed
  788.                 case AC_SAVE_AS_PCX_BW:
  789.                     WindowManager::hide_window();   // Hide file_sys
  790.                     WindowManager::hide_window();   // Hide file_menu
  791.                     moveTo(1);
  792.                     return 0;
  793.  
  794.                 default:
  795.                     return 0;
  796.         }
  797.     }
  798.     }
  799. //////////////////////
  800.  
  801. File VECTMAIN.CPP
  802.  
  803.  
  804. #include <alloc.h>      // The example of simple graphics editor interface
  805. #include <iostream.h>   // creation. The program shows linemenu with
  806. #include <conio.h>    // Paint Brush like choices: File, Edit, View etc.,
  807.             // Help system explains the behavior of package
  808.  
  809. #include "vector.h"
  810.  
  811. extern unsigned _stklen = 16000; // In some cases it is usefull
  812.  
  813. void main()
  814.     {
  815.     if(!init_KNOW_HOW(DETECT, 1))   // Initialization
  816.         return;
  817.     ///////////////////////////     // Hypertext help system.
  818.     rect r_help(5, 5, 70, 25);
  819.     help_object = new HypertextView(r_help, "vector.hlp", "_help.pcy",
  820.                   MOVE | RESIZE,
  821.                   pScreenSet->sub_interval,
  822.                                   SHOW_BORDER, 10, "VECTOR",
  823.                                   BLUE, YELLOW, 56);
  824. // Constructor
  825.     Vector* v = new Vector("vector.pcy", "work.buf");
  826. // Show object
  827.     v->show();
  828. // Run program
  829.     v->exe();      // process the program
  830. // Destructors
  831.     delete help_object;
  832.     delete v;
  833. // Close KH and BGI
  834.     close_KNOW_HOW();
  835.     closegraph();
  836.     }
  837.  
  838. *****************************************************************************
  839.  
  840.  
  841.